package com.fivetalks.client;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.fivetalks.object.Member;

public class SingleChatActivity extends Activity {

	DBConnect db;
	Member member;

	ListView list;

	ArrayList<Member> memberList;
	LoveCustomAdapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_single_chat);
		Intent intent = getIntent();
		member = (Member) intent.getSerializableExtra("member");

		Log.d("single", "welcome");

		list = (ListView) findViewById(R.id.list);
		list = (ListView) findViewById(R.id.list);
		memberList = new ArrayList<Member>();
		mAdapter = new LoveCustomAdapter(this, R.layout.loveroom_row,
				memberList);
		list.setAdapter(mAdapter);

		db = DBConnect.open(this);
//		db.DeleteDB(member.getId());
		Cursor c = db.selectDBWhere(member.getId());
		c.moveToFirst();
		while (c.moveToNext()) {
			Member member = new Member();
			member.setNickname(c.getString(1));
			member.setEmail(c.getString(2));
			addResult(member);
			Log.d("single", c.getString(2));

		}
		db.close();
	}

	public void addResult(Member member) {
		memberList.add(member);
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				mAdapter.notifyDataSetChanged();
			}
		});
	}

}
